﻿Imports System.ComponentModel
Imports DevExpress.LookAndFeel
Imports DevExpress.XtraCharts
Imports System.Text
Imports System.Globalization
Imports DevExpress.Utils
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports Microsoft.VisualBasic
Imports System.Linq
Imports System.Data.SqlClient
Imports System.Data.Linq.SqlClient.SqlMethods


Public Class fDashBoard
    Public argument As String
    Sub New()
        InitSkins()
        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

    End Sub
    Sub InitSkins()
        DevExpress.Skins.SkinManager.EnableFormSkins()
        DevExpress.UserSkins.BonusSkins.Register()
        UserLookAndFeel.Default.SetSkinStyle("Metropolis")
    End Sub

    Private Sub fDashBoard_Load(sender As Object, e As EventArgs) Handles MyBase.Load
      
        Application.DoEvents()

        'TODO: This line of code loads data into the 'DsIDebitos.dboardAntiguidadeSaldo' table. You can move, or remove it, as needed.
        'Me.DboardAntiguidadeSaldoTableAdapter.Fill(Me.DsIDebitos.dboardAntiguidadeSaldo)
        ''TODO: This line of code loads data into the 'DsIDebitos1.dboardIDebitos' table. You can move, or remove it, as needed.
        'Me.DboardIDebitosTableAdapter.Fill(Me.DsIDebitos1.dboardIDebitos)
        ''TODO: This line of code loads data into the 'DsIDebitos.Dashboard' table. You can move, or remove it, as needed.
        'Me.DashboardTableAdapter.Fill(Me.DsIDebitos.Dashboard)


        ' TryCast(ChartControl1.Diagram, XYDiagram).AxisX.NumericOptions.Format = NumericFormat.Currency



        Dim db As New lqTesourariaDataContext


        'LETRAS PARA ACEITE
        Dim ltaceite = (From c In db.tblCarteraDocs _
                        Where c.Accepted = 2 AndAlso c.Payment_Method_Code = "LETRAS" AndAlso c.Company = GlobalVariables.Empresa _
                        Select c.Remaining_Amt___LCY_).Sum

        LabelControl15.Text = FormatNumber(ltaceite / 1000, 0, TriState.False) & "k"

        'LETRAS CARTEIRA
        Dim ltcarteira = (From c In db.tblCarteraDocs _
                          Where c.Accepted = 1 AndAlso c.Payment_Method_Code = "LETRAS" AndAlso c.Company = GlobalVariables.Empresa _
                          Select c.Remaining_Amt___LCY_).Sum

        LabelControl17.Text = FormatNumber(ltcarteira / 1000, 0, TriState.False) & "k"

        'LETRAS DESCONTADAS
        Dim ltdescontadas = (From c In db.tblPostedCarteraDocs Join d In db.tblPostedBillGroups On c.Bill_Gr__Pmt__Order_No_ Equals d.No_ _
                             Where c.Bill_Gr__Pmt__Order_No_ <> "" AndAlso c.Payment_Method_Code = "LETRAS" AndAlso c.Company = GlobalVariables.Empresa AndAlso d.Company = GlobalVariables.Empresa _
                          Select c.Remaining_Amt___LCY_).Sum

        LabelControl19.Text = FormatNumber(ltdescontadas / 1000, 0, TriState.False) & "k"

        'CHEQUES CARTEIRA
        Dim chqcarteira = (From c In db.tblCarteraDocs _
                          Where c.Payment_Method_Code Like "CH*" _
                          Select c.Remaining_Amt___LCY_).Sum

        LabelControl21.Text = FormatNumber(chqcarteira / 1000, 0, TriState.False) & "k"

        'CHEQUES DESCONTADOS
        Dim chqdescontadas = (From c In db.tblPostedCarteraDocs Join d In db.tblPostedBillGroups On c.Bill_Gr__Pmt__Order_No_ Equals d.No_ _
                            Where c.Bill_Gr__Pmt__Order_No_ <> "" AndAlso c.Payment_Method_Code Like "CH*" AndAlso c.Company = GlobalVariables.Empresa AndAlso d.Company = GlobalVariables.Empresa _
                         Select c.Remaining_Amt___LCY_).Sum

        LabelControl23.Text = FormatNumber(chqdescontadas / 1000, 0, TriState.False) & "k"

        'CONTACTOS - INTERACÇÕES

        Dim curCulture As System.Globalization.CultureInfo = System.Globalization.CultureInfo.CurrentCulture

        Dim semana = curCulture.Calendar.GetWeekOfYear(Today(), curCulture.DateTimeFormat.CalendarWeekRule, curCulture.DateTimeFormat.FirstDayOfWeek)
        Dim ano = Year(Today())


        Dim contactos = (From c In db.tblInteractionLogEntries _
                         Where c.Semana = semana AndAlso c.Date.Value.Year = ano AndAlso c.Interaction_Template_Code = "cobrança" AndAlso c.Company = GlobalVariables.Empresa _
                         Select c.Contact_No_)

        LabelControl25.Text = contactos.Count

        'CLIENTES - INTERACÇÕES

        Dim clientescontactdos = (From c In db.tblInteractionLogEntries _
                         Where c.Semana = semana AndAlso c.Date.Value.Year = ano AndAlso c.Interaction_Template_Code = "cobrança" AndAlso c.Company = GlobalVariables.Empresa _
                         Group c By c.Contact_No_ Into Group _
                         Select Contact_No_)

        LabelControl27.Text = clientescontactdos.Count

        'NUMERO FACTURAS

        Dim FACTURAS = (From c In db.tblSalesInvoiceHeaders _
                        Where c.Semana = semana AndAlso c.Posting_Date.Value.Year = ano AndAlso c.Company = GlobalVariables.Empresa _
                        Group c By c.No_ Into Group _
                        Select No_)

        LabelControl29.Text = FACTURAS.Count

        'VALOR FACTURAS

        Dim VLFACTURAS = (From c In db.tblSalesInvoiceLines _
                        Where c.Semana = semana AndAlso c.Posting_Date.Value.Year = ano AndAlso c.Company = GlobalVariables.Empresa _
                        Select c.Amount_Including_VAT)


        LabelControl31.Text = FormatNumber(VLFACTURAS.Sum / 1000, 0, TriState.False) & "k"

        'NUMERO RECIBOS

        Dim RECIBOS = (From c In db.tblCustomerLedgerEntries _
                        Where c.Semana = semana AndAlso c.Posting_Date.Value.Year = ano AndAlso c.No__Series Like "D-RC*" AndAlso c.Company = GlobalVariables.Empresa _
                        Group c By c.Document_No_ Into Group _
                        Select Document_No_)

        LabelControl33.Text = RECIBOS.Count


        'VALOR RECIBOS

        Dim VLRECIBOS = (From c In db.tblCustomerLedgerEntries _
                        Where c.Semana = semana AndAlso c.Posting_Date.Value.Year = ano AndAlso c.No__Series Like "D-RC*" AndAlso c.Company = GlobalVariables.Empresa _
                        Select c.Amount__LCY__stats_)

        LabelControl35.Text = FormatNumber(VLRECIBOS.Sum / -1000, 0, TriState.False) & "k"


        'CONTACTAR 30D
        Dim dateOfFirstDay As DateTime = GetfirstOfWeek(DateTime.Now)
        Dim dateOflastDay As DateTime = GetlastOfWeek(DateTime.Now)

        Dim trintad = (From c In db.tblCustomerLedgerEntries _
                   Where c.Due_Date.Value.Date <= dateOflastDay.ToString AndAlso c.Remaining_Amount__LCY__stats_ > 0 AndAlso DateDiffDay(c.Due_Date.Value.Date, Today()) <= 30 AndAlso c.Company = GlobalVariables.Empresa _
                   Group c By c.Customer_No_ Into Group _
                   Select Customer_No_).Count

        LabelControl37.Text = trintad

        'CONTACTAR 60D

        Dim sessentad = (From c In db.tblCustomerLedgerEntries _
                   Where c.Due_Date.Value.Date <= dateOflastDay.ToString AndAlso c.Remaining_Amount__LCY__stats_ > 0 AndAlso DateDiffDay(c.Due_Date.Value.Date, Today()) <= 60 AndAlso DateDiffDay(c.Due_Date.Value.Date, Today()) > 30 AndAlso c.Company = GlobalVariables.Empresa _
                   Group c By c.Customer_No_ Into Group _
                   Select Customer_No_).Count

        LabelControl39.Text = sessentad

        'CONTACTAR 90D

        Dim noventad = (From c In db.tblCustomerLedgerEntries _
                   Where c.Due_Date.Value.Date <= dateOflastDay.ToString AndAlso c.Remaining_Amount__LCY__stats_ > 0 AndAlso DateDiffDay(c.Due_Date.Value.Date, Today()) <= 90 AndAlso DateDiffDay(c.Due_Date.Value.Date, Today()) > 60 AndAlso c.Company = GlobalVariables.Empresa _
                   Group c By c.Customer_No_ Into Group _
                   Select Customer_No_).Count

        LabelControl41.Text = noventad

        


        ' MEDIA DIAS EM ATRASO

        'TODO: This line of code loads data into the 'DsIDebitos2.dboardMDA' table. You can move, or remove it, as needed.
        Me.DboardMDATableAdapter.Fill(Me.DsIDebitos2.dboardMDA, GlobalVariables.Empresa)

        LabelControl45.Text = FormatNumber(DboardMDATableAdapter.GetData(GlobalVariables.Empresa).Item(0).Expr1.ToString, 0)


        'MEDIA DIAS VENCIMENTO

        Me.DboardMDVencimentoTableAdapter.Fill(Me.DsIDebitos.dboardMDVencimento, GlobalVariables.Empresa)

        LabelControl47.Text = FormatNumber(DboardMDVencimentoTableAdapter.GetData(GlobalVariables.Empresa).Item(0).Expr1.ToString, 0)


        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        'GRAFICO E LABELS VALORES EM DÉBITO

        Dim vencidomes = (From c In db.tblCustomerLedgerEntries Join d In db.tblDetailedCustomerLedgerEntries On c.Entry_No_ Equals d.Cust__Ledger_Entry_No_ _
                        Where d.Customer_Posting_Group <> "nac-duv" AndAlso d.Customer_Posting_Group <> "" AndAlso d.Initial_Entry_Due_Date < Today AndAlso d.Posting_Date <= Today AndAlso c.Company = GlobalVariables.Empresa AndAlso d.Company = GlobalVariables.Empresa _
                        Select d.Amount__LCY_).Sum

        Dim mesactual = (From c In db.tblDescricaoMeses _
                       Where c.Mes = Today.Month _
                       Select c.MesDesc).SingleOrDefault

        Dim series2 As New Series("Vencido", ViewType.StackedArea)

        ' Add points to it.
        series2.Points.Add(New SeriesPoint(mesactual, vencidomes))
        For i As Integer = 0 To 4
            Dim datahoje As New DateTime(Today.Year, Today.Month, 1)
            Dim data As DateTime = datahoje.AddMonths(-i).AddDays(-1)

            Dim vencidomesn = (From c In db.tblCustomerLedgerEntries Join d In db.tblDetailedCustomerLedgerEntries On c.Entry_No_ Equals d.Cust__Ledger_Entry_No_ _
                        Where d.Customer_Posting_Group <> "nac-duv" AndAlso d.Customer_Posting_Group <> "" AndAlso d.Initial_Entry_Due_Date < data AndAlso d.Posting_Date <= data AndAlso c.Company = GlobalVariables.Empresa AndAlso d.Company = GlobalVariables.Empresa _
                        Select d.Amount__LCY_).Sum

            Dim mes = (From c In db.tblDescricaoMeses _
                       Where c.Mes = data.Month _
                       Select c.MesDesc).SingleOrDefault

            series2.Points.Add(New SeriesPoint(mes, vencidomesn))

        Next

        Dim series1 As New Series("Não Vencido", ViewType.StackedArea)

        Dim nvencidomes = (From c In db.tblCustomerLedgerEntries Join d In db.tblDetailedCustomerLedgerEntries On c.Entry_No_ Equals d.Cust__Ledger_Entry_No_ _
                         Where d.Customer_Posting_Group <> "nac-duv" AndAlso d.Customer_Posting_Group <> "" AndAlso d.Initial_Entry_Due_Date >= Today AndAlso d.Posting_Date <= Today AndAlso c.Company = GlobalVariables.Empresa AndAlso d.Company = GlobalVariables.Empresa _
                         Select d.Amount__LCY_).Sum

        series1.Points.Add(New SeriesPoint(mesactual, nvencidomes))

        For i As Integer = 0 To 4
            Dim datahoje As New DateTime(Today.Year, Today.Month, 1)
            Dim data As DateTime = datahoje.AddMonths(-i).AddDays(-1)

            Dim nvencidomesn = (From c In db.tblCustomerLedgerEntries Join d In db.tblDetailedCustomerLedgerEntries On c.Entry_No_ Equals d.Cust__Ledger_Entry_No_ _
                        Where d.Customer_Posting_Group <> "nac-duv" AndAlso d.Customer_Posting_Group <> "" AndAlso d.Initial_Entry_Due_Date >= data AndAlso d.Posting_Date <= data AndAlso c.Company = GlobalVariables.Empresa AndAlso d.Company = GlobalVariables.Empresa _
                        Select d.Amount__LCY_).Sum

            Dim mes = (From c In db.tblDescricaoMeses _
                       Where c.Mes = data.Month _
                       Select c.MesDesc).SingleOrDefault

            series1.Points.Add(New SeriesPoint(mes, nvencidomesn))

        Next


        ' Add the series to the chart.
        ChartControl4.Series.Add(series1)
        ChartControl4.Series.Add(series2)

        ' Set the numerical argument scale types for the series,
        ' as it is qualitative, by default.
        series1.ArgumentScaleType = ScaleType.Qualitative
        series2.ArgumentScaleType = ScaleType.Qualitative
        series2.SeriesPointsSorting = SortingMode.Ascending
        series1.SeriesPointsSorting = SortingMode.Ascending



        ' Access the type-specific options of the diagram.
        CType(ChartControl4.Diagram, XYDiagram).AxisX.Range.SideMarginsEnabled = False

        ' Hide the legend (if necessary).
        ChartControl4.Legend.Visible = True

        ' Add a title to the chart (if necessary).
        ChartControl4.Titles(0).Text = "Valores em Débito"
        ChartControl4.Titles(0).Alignment = StringAlignment.Near

        Dim lblVencido As Double = FormatNumber(ChartControl4.Series("Vencido").Points(0).Values.GetValue(0).ToString, 0, TriState.False)
        Dim lblNVencido As Double = FormatNumber(ChartControl4.Series("Não Vencido").Points(0).Values.GetValue(0).ToString, 0, TriState.False)

        LabelControl5.Text = FormatNumber(lblNVencido / 1000, 0, TriState.False) & "k"
        LabelControl6.Text = FormatNumber(lblVencido / 1000, 0, TriState.False) & "k"
        LabelControl4.Text = FormatNumber((lblNVencido + lblVencido) / 1000, 0, TriState.False) & "k"


        For i As Integer = 0 To 7
            Dim customAxisLabel As New CustomAxisLabel()

            customAxisLabel.AxisValue = (i + 1) * 1000000
            customAxisLabel.Name = String.Format("{0}M", (i + 1) * 1)
            TryCast(ChartControl4.Diagram, XYDiagram).AxisY.CustomLabels.Add(customAxisLabel)
        Next i



        TryCast(ChartControl4.Diagram, XYDiagram).AxisY.Range.MaxValue = 8000000



        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        'GRAFICO E LABELS ANTIGUIDADE SALDO

        Dim SerieAntiguidade As New Series("Antiguidade", ViewType.SplineArea)

        Dim AntiguidadeDiasmes As Double = DboardAntiguidadeSaldoTableAdapter.GetData(Today, GlobalVariables.Empresa).Item(0).DIAS.ToString
        Dim AntDiasMesDesc = (From c In db.tblDescricaoMeses _
                   Where c.Mes = Today.Month _
                   Select c.MesDesc).SingleOrDefault

        SerieAntiguidade.Points.Add(New SeriesPoint(AntDiasMesDesc, AntiguidadeDiasmes))

        For i As Integer = 0 To 4
            Dim datahoje As New DateTime(Today.Year, Today.Month, 1)
            Dim data As DateTime = datahoje.AddMonths(-i).AddDays(-1)

            Dim AntiguidadeDiasmesn As Double = DboardAntiguidadeSaldoTableAdapter.GetData(data, GlobalVariables.Empresa).Item(0).DIAS.ToString

            Dim mesn = (From c In db.tblDescricaoMeses _
                       Where c.Mes = data.Month _
                       Select c.MesDesc).SingleOrDefault


            SerieAntiguidade.Points.Add(New SeriesPoint(mesn, AntiguidadeDiasmesn))

        Next

        ChartControl1.Series.Add(SerieAntiguidade)

        SerieAntiguidade.ArgumentScaleType = ScaleType.Qualitative
        SerieAntiguidade.SeriesPointsSorting = SortingMode.Ascending

        CType(ChartControl1.Diagram, XYDiagram).AxisX.Range.SideMarginsEnabled = False

        'ANTIGUIDADE DE SALDO

        LabelControl43.Text = ChartControl1.Series("Antiguidade").Points(0).Values.GetValue(0).ToString



        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        'GRAFICO IDADE DE DEBITOS

        Dim SerieTrintaDias As New Series("30", ViewType.Bar)
        Dim SerieQuarentaCincoDias As New Series("45", ViewType.Bar)
        Dim SerieSessentaDias As New Series("60", ViewType.Bar)
        Dim SerieNoventaDias As New Series("90", ViewType.Bar)
        Dim SerieCentoVinteDias As New Series("120", ViewType.Bar)
        Dim SerieMCentoVinteDias As New Series(">120", ViewType.Bar)



        Dim TrintaDiasGrafico = (From c In db.tblCustomerLedgerEntries Join d In db.tblDetailedCustomerLedgerEntries On c.Entry_No_ Equals d.Cust__Ledger_Entry_No_ _
                        Where d.Customer_Posting_Group <> "nac-duv" AndAlso d.Customer_Posting_Group <> "" AndAlso d.Initial_Entry_Due_Date <= Today AndAlso d.Posting_Date <= Today AndAlso DateDiffDay(c.Due_Date, Today) <= 30 AndAlso DateDiffDay(c.Due_Date, Today) > 0 AndAlso c.Company = GlobalVariables.Empresa AndAlso d.Company = GlobalVariables.Empresa _
                        Select d.Amount__LCY_).Sum

        Dim QuarentaCincoDiasGrafico = (From c In db.tblCustomerLedgerEntries Join d In db.tblDetailedCustomerLedgerEntries On c.Entry_No_ Equals d.Cust__Ledger_Entry_No_ _
                        Where d.Customer_Posting_Group <> "nac-duv" AndAlso d.Customer_Posting_Group <> "" AndAlso d.Initial_Entry_Due_Date <= Today AndAlso d.Posting_Date <= Today AndAlso DateDiffDay(c.Due_Date, Today) <= 45 AndAlso DateDiffDay(c.Due_Date, Today) > 30 AndAlso c.Company = GlobalVariables.Empresa AndAlso d.Company = GlobalVariables.Empresa _
                        Select d.Amount__LCY_).Sum

        Dim SessentaDiasGrafico = (From c In db.tblCustomerLedgerEntries Join d In db.tblDetailedCustomerLedgerEntries On c.Entry_No_ Equals d.Cust__Ledger_Entry_No_ _
                       Where d.Customer_Posting_Group <> "nac-duv" AndAlso d.Customer_Posting_Group <> "" AndAlso d.Initial_Entry_Due_Date <= Today AndAlso d.Posting_Date <= Today AndAlso DateDiffDay(c.Due_Date, Today) <= 60 AndAlso DateDiffDay(c.Due_Date, Today) > 45 AndAlso c.Company = GlobalVariables.Empresa AndAlso d.Company = GlobalVariables.Empresa _
                       Select d.Amount__LCY_).Sum

        Dim NoventaDiasGrafico = (From c In db.tblCustomerLedgerEntries Join d In db.tblDetailedCustomerLedgerEntries On c.Entry_No_ Equals d.Cust__Ledger_Entry_No_ _
               Where d.Customer_Posting_Group <> "nac-duv" AndAlso d.Customer_Posting_Group <> "" AndAlso d.Initial_Entry_Due_Date <= Today AndAlso d.Posting_Date <= Today AndAlso DateDiffDay(c.Due_Date, Today) <= 90 AndAlso DateDiffDay(c.Due_Date, Today) > 60 AndAlso c.Company = GlobalVariables.Empresa AndAlso d.Company = GlobalVariables.Empresa _
               Select d.Amount__LCY_).Sum

        Dim CentoVinteDiasGrafico = (From c In db.tblCustomerLedgerEntries Join d In db.tblDetailedCustomerLedgerEntries On c.Entry_No_ Equals d.Cust__Ledger_Entry_No_ _
       Where d.Customer_Posting_Group <> "nac-duv" AndAlso d.Customer_Posting_Group <> "" AndAlso d.Initial_Entry_Due_Date <= Today AndAlso d.Posting_Date <= Today AndAlso DateDiffDay(c.Due_Date, Today) <= 120 AndAlso DateDiffDay(c.Due_Date, Today) > 90 AndAlso c.Company = GlobalVariables.Empresa AndAlso d.Company = GlobalVariables.Empresa _
       Select d.Amount__LCY_).Sum

        Dim MCentoVinteDiasGrafico = (From c In db.tblCustomerLedgerEntries Join d In db.tblDetailedCustomerLedgerEntries On c.Entry_No_ Equals d.Cust__Ledger_Entry_No_ _
       Where d.Customer_Posting_Group <> "nac-duv" AndAlso d.Customer_Posting_Group <> "" AndAlso d.Initial_Entry_Due_Date <= Today AndAlso d.Posting_Date <= Today AndAlso DateDiffDay(c.Due_Date, Today) > 120 AndAlso c.Company = GlobalVariables.Empresa AndAlso d.Company = GlobalVariables.Empresa _
       Select d.Amount__LCY_).Sum


        SerieTrintaDias.Points.Add(New SeriesPoint("Dias", TrintaDiasGrafico))
        SerieQuarentaCincoDias.Points.Add(New SeriesPoint("Dias", QuarentaCincoDiasGrafico))
        SerieSessentaDias.Points.Add(New SeriesPoint("Dias", SessentaDiasGrafico))
        SerieNoventaDias.Points.Add(New SeriesPoint("Dias", NoventaDiasGrafico))
        SerieCentoVinteDias.Points.Add(New SeriesPoint("Dias", CentoVinteDiasGrafico))
        SerieMCentoVinteDias.Points.Add(New SeriesPoint("Dias", MCentoVinteDiasGrafico))


        ChartControl2.Series.Add(SerieTrintaDias)
        ChartControl2.Series.Add(SerieQuarentaCincoDias)
        ChartControl2.Series.Add(SerieSessentaDias)
        ChartControl2.Series.Add(SerieNoventaDias)
        ChartControl2.Series.Add(SerieCentoVinteDias)
        ChartControl2.Series.Add(SerieMCentoVinteDias)

        For i As Integer = 0 To 10.5
            Dim customAxisLabel As New CustomAxisLabel()

            customAxisLabel.AxisValue = (i + 1) * 100000
            customAxisLabel.Name = String.Format("{0}k", (i + 1) * 100)
            TryCast(ChartControl2.Diagram, XYDiagram).AxisY.CustomLabels.Add(customAxisLabel)
        Next i

        TryCast(ChartControl2.Diagram, XYDiagram).AxisY.Range.MaxValue = TrintaDiasGrafico + 50000


        ChartControl2.CrosshairEnabled = DefaultBoolean.True
        ChartControl2.RuntimeHitTesting = True


    End Sub


    Private Sub ChartControl2_MouseClick(sender As Object, e As MouseEventArgs) Handles ChartControl2.MouseClick
        ' Obtain the object being clicked. 

        Dim hi As ChartHitInfo = ChartControl2.CalcHitInfo(e.X, e.Y)

        ' Check whether it was a series point, and if so -  
        ' obtain its argument, and pass it to the detail series. 
        Dim point As Series = hi.Series

        If point IsNot Nothing Then
            argument = point.ToString()

            MessageBox.Show(argument)




            '' Flip the series. 
            'If ChartControl1.Series(0).Visible = True Then
            '    ChartControl1.Series(0).Visible = False

            '    ChartControl1.Series(1).Name = argument
            '    ChartControl1.Series(1).Visible = True

            '    ' Since the new series determines another diagram's type, 
            '    ' you should re-define axes properties. 
            '    Dim diagram As XYDiagram = CType(ChartControl1.Diagram, XYDiagram)
            '    diagram.AxisX.Label.Angle = -25
            '    diagram.AxisY.NumericOptions.Format = NumericFormat.Currency
            '    diagram.AxisY.NumericOptions.Precision = 0

            '    ChartControl1.Series(1).DataFilters(0).Value = argument

            '    ChartControl1.Titles(0).Visible = True
            '    ChartControl1.Titles(1).Text = "Personal Sales by Categories"


            '  End If
        Else

        End If

        ' Obtain the title under the test point. 
        Dim link As ChartTitle = hi.ChartTitle

        ' Check whether the link was clicked, and if so -  
        ' restore the main series. 
        'If link IsNot Nothing AndAlso link.Text.StartsWith("Back") Then
        '    ChartControl1.Series(0).Visible = True
        '    ChartControl1.Series(1).Visible = False

        '    link.Visible = False
        '    ChartControl1.Titles(1).Text = "Sales by Person"
        'End If
    End Sub

    Private Sub TileControl1_Click(sender As Object, e As EventArgs)

    End Sub
    Public Function GetfirstOfWeek(ByRef Dt As DateTime) As DateTime
        Return Dt.AddDays(-Dt.DayOfWeek + 1)
    End Function

    Public Function GetlastOfWeek(ByRef Dt As DateTime) As DateTime
        Return Dt.AddDays(-Dt.DayOfWeek + 7)
    End Function
    Public Shared Function DateDiffa( _
    datePartArg As String, _
    startDate As String, _
    endDate As String _
) As Nullable(Of Integer)

    End Function

End Class